package com.fz.us.admin.company.entity;

import javax.persistence.*;
import java.util.Set;

/**
 * 实体类 - 部门
 * ============================================================================
 * 版权所有 2016 。
 *
 * @author fallenpanda
 * @version 1.0 2016-07-25 。
 * ============================================================================
 */
@Entity
@Table(name="sys_department")
public class Department extends CompanyEntity {

    private static final long serialVersionUID = -4882896191937033197L;
    /**
     *令牌(要舍弃)
     */
    private String value;
    /**
     * path 分隔符
     */
    public static final String PATH_SEPARATOR = ",";

    /**
     * 部门代码
     */
    private String code;
    /**
     * 描述
     */
    private String description;
    /**
     * 排序
     */
    private int sortNo;
    /**
     * 父节点
     */
    private Department parent;

    /**
     * 岗位
     */
    private Set<Post> postSet;
    /**
     * 子节点
     */
    private Set<Department> children;
    /**
     * 职权
     */
    private Set<Power> powerSet;

    /**
     * 路径
     */
    private String path;
    /**
     * 层级
     */
    private int level;

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    @Column(length = 5000)
    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @Column(nullable = false)
    public int getSortNo() {
        return sortNo;
    }

    public void setSortNo(int sortNo) {
        this.sortNo = sortNo;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    public Department getParent() {
        return parent;
    }

    public void setParent(Department parent) {
        this.parent = parent;
    }

    @OneToMany(mappedBy = "department", fetch = FetchType.LAZY)
    @OrderBy("name asc")
    public Set<Power> getPowerSet() {
        return powerSet;
    }

    public void setPowerSet(Set<Power> powerSet) {
        this.powerSet = powerSet;
    }


    @OneToMany(mappedBy = "parent", fetch = FetchType.LAZY)
    @OrderBy("name asc")
    public Set<Department> getChildren() {
        return children;
    }

    public void setChildren(Set<Department> children) {
        this.children = children;
    }

    @ManyToMany(fetch = FetchType.LAZY)
    @OrderBy("name asc")
    public Set<Post> getPostSet() {
        return postSet;
    }

    public void setPostSet(Set<Post> postSet) {
        this.postSet = postSet;
    }

    public int getLevel() {
        return level;
    }

    public void setLevel(int level) {
        this.level = level;
    }

    @Column(length = 5000)
    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }
}
